package com.boarsoft.validate.jsonschema.everit;

import com.boarsoft.validate.jsonschema.JsonSchemaCache;
import org.everit.json.schema.Schema;
import org.everit.json.schema.ValidationException;
import org.everit.json.schema.loader.SchemaLoader;
import org.json.JSONObject;

import java.util.Map;

public class Validatior {

    public static void validate(String schemaId, Map<String,Object> obj){
        JSONObject jsonSchema = new JSONObject(JsonSchemaCache.getSchema(schemaId));
        JSONObject jsonSubject = new JSONObject(obj);

        Schema schema = SchemaLoader.load(jsonSchema);
        try {
            schema.validate(jsonSubject);
        }catch (ValidationException e){
            throw e;
        }
    }
}
